home *** CD-ROM | disk | FTP | other *** search
- PAGE 60,132
- TITLE TIMPARK1.ASM From File TPARK.ARC
-
- ; AUTHOR: Sanford Z. Zelovitz
- ; 714-894-6808
-
- ; Version 1.1, 03/19/86
- ;
- ; A resident program to park drive C and, if present, drive D
- ; after a delay of N minutes.
- ;
- ; To use the program, simply type or put in your batch file:
- ; TIMEPARK N
- ;
- ; where N is the number of minutes that you
- ; will allow before the disk parking takes
- ; place. Please note that the range of N is 1-9.
- ;
- ; I excerpted the documentation and annoted the program
- ; Lew Paper, 10/9/86
-
- code Segment Para
- Assume cs:code, ds:code
- org 100h
- park proc far
- jmp init ; Initialize
-
- ;********************************************************************
-
- ; VARIABLES FOR RESIDENT PORTION
-
- x1coff dw 0 ; Original timer interrupt 1CH offset
- x1cseg dw 0 ; Original timer interrupt 1CH segment
- x13off dw 0 ; Original disk interrupt 13H offset
- x13seg dw 0 ; Original disk interrupt 13H offset
- parked dw 0 ; 1 if there was a parking request and
- ; there has been no disk request since
- count dw 0 ; Number of timer ticks without a
- ; disk request left before the system
- ; issues a parking request
- value dw 0 ; Total number of timer ticks without
- ; a disk request before the system
- ; issues a parking request
- flag dw 0 ; 1 if the system is parking a head
- oldax dw 0 ; Storage for original AX when parking
- oldip dw 0 ; Storage for original IP when parking
- oldcs dw 0 ; Storage for original CS when parking
- oldflgs dw 0 ; Storage for original flags when
- ; parking
-
- ;********************************************************************
-
- ; TIMER INTERRUPT 1CH
-
- even
- x1cint: push ax ; Save registers used on stack
- push bx
- push cx
- push dx
- push ds
- mov ax,cs ; Establish value of DS
- mov ds,ax
- xor ax,ax ; 0 => AX
- cmp parked,ax ; Has the disk been parked?
- jne x1cext ; Yes. Go on to next timer function.
- dec word ptr count ; Number of timer ticks idle until park
- ; => count
- cmp count,ax ; Should we park now?
- jne x1cext ; No. Go on to next timer function
- cmp flag,1 ; Are we parking now?
- je x1cext ; Yes. Go on to next timer function
-
- ; Set up parking
- cli ; Enable interrupts
- mov ax,1 ; 1 => AX
- mov parked,ax ; Show we are parked
- mov flag,ax ; Show we are parking
- mov ax,value ; Reset count to number of timer ticks
- ; idle until park
- mov count,ax
- pop ds ; Restore registers to conditions at
- ; start of interrupt
- pop dx
- pop cx
- pop bx
- pop ax
- mov cs:oldax,ax ; Save so we can use AX to receive
- ; stack
- ; Now save the three words from the original interrupt call in memory
- pop ax ;ip
- mov cs:oldip,ax
- pop ax ;cs
- mov cs:oldcs,ax
- pop ax ;flags
- mov cs:oldflgs,ax
- ; Generate an interrupt return to the parker
- mov ax,offset parks
- pushf
- push cs
- push ax
- mov ax,cs:oldax ; Restore AX to its value before the
- ; interrupt
- sti ; Enable interrupts
- jmp dword ptr cs:[x1coff] ; Go on to the next timer function
- ; Will return to parks
-
- x1cext: jmp x1cout ; Target for short jumps on the way
- ; to the next timer function
-
- ; Actually park
- ; Note that registers are from the original interrupt call
- parks: sti ; Enable interrupts
- push ax ; Save registers
- push cx
- push dx
- push ds
- mov ax,cs ; Establish value of DS
- mov ds,ax
- ;
- ;
- ; Do the BIOS's dirty work so this code will work!
- ;
- mov al,020h ; 8259 end of interrupt command
- out 020h,al
- ;
- ;
- ;
- mov ah,08 ; Return parameters from disk table
- mov dx,80h ; Disk C:
- int 13h ; Disk interrupt
- mov dx,80h ; Disk C:
- ; The last useable cylinder is a 10 bit number. CH contains its
- ; low order 8 bits. Bits 7 and 8 of CL contain its high order 2
- ; bits.
- inc ch ; Get first unuseable cylinder number
- jnc p1
- add cl,40h ; Add carry to ninth bit
- p1: mov ax,0c01h ; Seek first unuseable sector
- int 13h ; Disk interrupt
- ;
- mov ah,08 ; Return parameters from disk table
- mov dx,81h ; Disk D:
- int 13h ; Disk interrupt
- mov dx,81h ; Disk D:
- inc ch ; Get first unuseable cylinder number
- jnc p2
- add cl,40h ; Add carry to ninth bit
- p2: mov ax,0c01h ; Seek first unuseable sector
- int 13h ; Disk interrupt
- ;
- xor ax,ax ; 0 => AX
- mov flag,ax ; Show that we are not parking
- pop ds ; Restore registers from original
- ; call
- pop dx
- pop cx
- mov ax,cs:oldflgs ; Restore original flags
- push ax
- popf
- pop ax ; Restore original AX
- jmp dword ptr cs:[oldip] ; Effectively a FAR RETURN to the
- ; original interrupt call
-
- ; Go on to the next timer function if no park
- x1cout: pop ds ; Restore registers
- pop dx
- pop cx
- pop bx
- pop ax
- x1cou1: jmp dword ptr cs:[x1coff] ; Go on to the next timer function
-
- ;********************************************************************
-
- ; DISK INTERRUPT 13H
-
- x13int: push ax ; Save registers
- push ds
- sti ; Enable interrupts
- mov ax,cs ; Establish value of DS
- mov ds,ax
- cmp flag,1 ; Are we parking?
- je x13in1 ; Yes. Assume this is a call from
- ; parking and go on to the next
- ; disk function
- mov ax,value ; Reset count to number of timer ticks
- ; until park
-
- mov count,ax
- xor ax,ax ; 0 => AX
- mov parked,ax ; Show we are not parked
- x13in1: pop ds ; Restore registers
- pop ax
- jmp dword ptr cs:[x13off] ; Go on to next disk function
- dw 0
- table dw 0 ; End of resident part
-
- ;********************************************************************
-
- ; INITIALIZATION
-
- init: xor ax,ax ; 0 => AX
- mov parked,ax ; Show we are not parked
- mov bx,80h ; Address of count of command line
- ; characters
- mov al,[bx] ; Count of command line characters
- cmp al,0 ; Is command line empty?
- jne init1 ; No. Get first character
- int 21h ; Return. Note that there is no
- ; explicit warning of the failure,
- ; only the lack of a sign on message.
-
- init1: inc bx ; Address of next command line
- ; character
- mov al,[bx] ; Next command line character
- cmp al,32 ; Is it a space?
- je init1 ; Yes. Get next command line
- ; character
- cmp al,13 ; Is it a carriage return, which
- ; marks the end of the command line?
- jne init3 ; No. Get number of minutes to wait
- init2: xor ax,ax ; 0 => AX
- int 21h ; Return with no message
-
- init3: cmp al,49 ; Is it less than ASCII 1?
- jb init2 ; Yes. Return with no message.
- cmp al,57 ; Is it greater than ASCII 9?
- ja init2 ; Yes. Return with no message.
- lea dx,mess ; Offset of sign on message
- mov cx,ax ; Temporarily save ASCII digit
- mov ah,09 ; Print string function
- int 21h
- mov ax,cx ; Restore ASCII digit
- xor ah,ah ; 0 => AH
- mov bx,0fh ; Converted digit to AX
- and ax,bx
- mov dx,1091 ; 60 * 18.2 = Number of timer ticks
- ; per minute
- mul dx ; Number of timer ticks idle until
- ; park => AX
- mov value,ax ; Number of timer ticks idle until
- ; park => value
- mov count,ax ; Number of timer ticks idle until
- ; park => count
-
- cli ; Disable interrupts
- push es ; Save register
- xor ax,ax ; 0 => AX
- mov es,ax ; 0 => ES
- mov bx,76 ; 4 * 13H
- mov ax,es:[bx] ; Offset of interrupt 13H => x13off
- mov x13off,ax
- mov ax,offset x13int ; Offset of x13int =>
- ; offset of interrupt 13H
- mov es:[bx],ax
- inc bx ; Offset of segment of interrupt
- ; 13H => BX
- inc bx
- mov ax,es:[bx] ; Segment of interrupt 13H => x13seg
- mov x13seg,ax
- mov ax,cs ; CS => segment of interrupt 13H
- mov es:[bx],ax
- xor ax,ax ; 0 => AX
- mov flag,ax ; Show that we are not parking
- mov es,ax ; 0 => ES
- mov bx,112 ; 4 * 1CH
- mov ax,es:[bx] ; Offset of interrupt 1CH => x1coff
- mov x1coff,ax
- mov ax,offset x1cint ; Offset of x1cint =>
- ; offset of interrupt 1CH
- mov es:[bx],ax
- inc bx ; Offset of segment of interrupt
- ; 1CH => BX
- inc bx
- mov ax,es:[bx] ; Segment of interrupt 1CH => x1cseg
- mov x1cseg,ax
- mov ax,cs ; CS => segment of interrupt 1CH
- mov es:[bx],ax
- pop es ; Restore register
- sti ; Enable interrupts
- mov dx,offset table ; Last offset to retain
- int 27h ; Terminate and stay resident
-
- ; INITIALIZATION VARIABLE
- mess db 'Alpha Computer Service timed parker is activated'
- db 13,10,'for hard disks C and, if present, D'
- db 13,10,'$'
- park endp
- code ends
- end park